﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace Wild2.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index(int? parameter)
        {
            Models.Pages.Home.Index page = new Models.Pages.Home.Index();
            Int32? UserID = Wild2.Models.Auth.AuthOnSite.GetUserId();
            if (UserID.HasValue)
            {
                if (Wild2.Models.TimeOnSite.TimeOnSite.GetTimeOnSite(UserID.Value).TotalMinutes < 10)
                {
                    page.infoMessage = String.Format(Resources.Home.Newbie, Response.ApplyAppPathModifier("~/Help.aspx/Index/1"));
                }
                Models.Favorites.Favorites.AddFavoriteToSession("Популярные записи");
                Wild2.Models.ViewTabs.ViewTabs.setCurrentTab(Url.RequestContext.RouteData.Values["controller"].ToString(), Url.RequestContext.RouteData.Values["action"].ToString());
            }
            else
            {
                //page.infoMessage = Wild2.Models.Guide.Guide.GetGuideText();    
            }
            //******************************************************
            Wild2.Models.Pages.Controls.PagingTop pt = new Wild2.Models.Pages.Controls.PagingTop();
            if (UserID.HasValue)
            {
                pt.PreviousLink = Url.Action("Subscr", "Blog", new { parameter = 0 });
                pt.PreviousName = "Лента друзей";
            }
            else
            {
                pt.PreviousLink = Url.Action("Sandbox", "Blog", new { parameter = 0 });
                pt.PreviousName = "Песочница";
            }
            pt.CurrentName = "Популярные";
            pt.NextLink = Url.Action("All", "Blog", new { parameter = 0 });
            pt.NextName = "Все записи";
            page.pt = pt;
            //******************************************************

            //******************************************************
            Wild2.Models.Pages.Controls.BlogsTopicList btl = new Models.Pages.Controls.BlogsTopicList();
            //if (parameter.HasValue) btl.TopicList = Models.Blog.Blog.GetTopicsPopular(parameter.Value);
            //else btl.TopicList = Models.Blog.Blog.GetTopicsPopular(0);
            if (parameter.HasValue) btl.TopicList = Models.Blog.Blog.GetTopics(parameter.Value);
            else btl.TopicList = Models.Blog.Blog.GetTopics(0);
            page.btl = btl;
            //******************************************************

            //******************************************************
            Wild2.Models.Pages.Controls.PagingBottom pb = new Wild2.Models.Pages.Controls.PagingBottom();
            if (parameter.HasValue)
            {
                pb.PreviousLink = Url.Action("Index", new { parameter = parameter + 1 });
                if (parameter > 0)
                {
                    pb.NextLink = Url.Action("Index", new { parameter = parameter - 1 });
                }
            }
            else
            {
                pb.PreviousLink = Url.Action("Index", new { parameter = 1 });
            }
            page.pb = pb;
            //******************************************************

            return View(page);
        }
    }
}
